﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WindowsFormsTest.Reserve;
using System.Diagnostics;
using WindowsFormsTest.Public;
using WindowsFormsTest.Sell;

namespace WindowsFormsTest
{
   
    
   
    public enum ManagerModel{
        DEFAULT,SEARCH
    }
    public enum PanelModel
    {
        DEFAULT,ONLY_CONTROL
    }
   
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            //this.skinEngine1.SkinFile = "./skin/msn.ssk"; 




            Operator.Create_MainTabPage(OperatorLabelEnum.HOME,WindowModel.DEFAULT,this);
                   //工作台
                new OperatorButton(OperatorLabelEnum.RESERVE_SEARCH, this.flowLayoutPanel7, this).Create_Operator_Btn();
                new OperatorButton(OperatorLabelEnum.ORDER_AUDIT, this.flowLayoutPanel7, this).Create_Operator_Btn();
                new OperatorButton(OperatorLabelEnum.PURCHASE_AUDIT, this.flowLayoutPanel7, this).Create_Operator_Btn();
          
                   //销售
                   new OperatorButton(OperatorLabelEnum.ORDER_MANAGER,this.flowLayoutPanel6,this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.ORDER_ADD,this.flowLayoutPanel6,this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.ORDER_REJECT,this.flowLayoutPanel6,this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.ORDER_AUDIT,this.flowLayoutPanel6,this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.ORDER_COMPARE,this.flowLayoutPanel6,this).Create_Operator_Btn();

                   //采购
                   new OperatorButton(OperatorLabelEnum.PURCHASE_PRICE, this.flowLayoutPanel2, this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.PURCHASE_PLAN, this.flowLayoutPanel2, this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.PURCHASE_MANAGER, this.flowLayoutPanel2, this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.PURCHASE_ADD, this.flowLayoutPanel2, this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.PURCHASE_AUDIT, this.flowLayoutPanel2, this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.PURCHASE_PAY, this.flowLayoutPanel2, this).Create_Operator_Btn();
                   new OperatorButton(OperatorLabelEnum.PURCHASE_REJECT, this.flowLayoutPanel2, this).Create_Operator_Btn();
           
                    //库存管理
            new OperatorButton(OperatorLabelEnum.RESERVE_SEARCH, this.flowLayoutPanel5, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.RESERVE_IN, this.flowLayoutPanel5, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.RESERVE_OUT, this.flowLayoutPanel5, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.RESERVE_MOVE, this.flowLayoutPanel5, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.RESERVE_COUNT, this.flowLayoutPanel5, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.RESERVE_PRODUCTMANAGER, this.flowLayoutPanel5, this).Create_Operator_Btn();

            //进销存管理
            new OperatorButton(OperatorLabelEnum.BUSIMANAGER_CUSTOM, this.flowLayoutPanel3, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.BUSIMANAGER_PROVIDE, this.flowLayoutPanel3, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.BUSIMANAGER_TEMPLATE, this.flowLayoutPanel3, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.BUSIMANAGER_STORAGE, this.flowLayoutPanel3, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.BUSIMANAGER_TODO, this.flowLayoutPanel3, this).Create_Operator_Btn();

            //系统管理
            new OperatorButton(OperatorLabelEnum.SYSTEM_USER, this.flowLayoutPanel1, this).Create_Operator_Btn();
            new OperatorButton(OperatorLabelEnum.SYSTEM_ROLE, this.flowLayoutPanel1, this).Create_Operator_Btn();
             new OperatorButton(OperatorLabelEnum.SYSTEM_POST, this.flowLayoutPanel1, this).Create_Operator_Btn();
             new OperatorButton(OperatorLabelEnum.SYSTEM_DEPT, this.flowLayoutPanel1, this).Create_Operator_Btn();
             new OperatorButton(OperatorLabelEnum.SYSTEM_LOGGER, this.flowLayoutPanel1, this).Create_Operator_Btn();
             new OperatorButton(OperatorLabelEnum.SYSTEM_DATABAK, this.flowLayoutPanel1, this).Create_Operator_Btn();
             new OperatorButton(OperatorLabelEnum.SYSTEM_PARAM, this.flowLayoutPanel1, this).Create_Operator_Btn();
        }
       
        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //this.WindowState=System.Windows.Forms.FormWindowState.Maximized;
        }

        private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
        {

        }

        private void splitContainer2_DoubleClick(object sender, EventArgs e)
        {
            //this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Top;
        }

        private void splitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
        {

        }

        private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
           
        }

        private void button7_Click(object sender, EventArgs e)
        {
        //    UserControl2 u2 = new UserControl2();

        //    TabPage tb = new TabPage();
        //    tb.Text = "abcccc";
        //    tb.Controls.Add(u2);
            
        //    //tb.TabIndex = this.tabControl2.Controls.Count; 
        //    this.tabControlMain.TabPages.Add(tb);

        //    this.tabControlMain.SelectedTab=tb;
             
        }

        private void tabControl2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            TabControl tabControl1 = (TabControl)sender;
            Point pt = new Point(e.X, e.Y);
            for (int i = 0; i < tabControl1.TabCount; i++)
            {
                Rectangle recTab = tabControl1.GetTabRect(i);
                if (recTab.Contains(pt))
                {
                    TabPage seltab = this.tabControlMain.SelectedTab;
                    int seltabindex = this.tabControlMain.SelectedIndex;
                    tabControlMain.Controls.Remove(seltab);
                    int newSelTabIndex = seltabindex;
                    if (seltabindex != 0)
                    {
                        newSelTabIndex = seltabindex - 1;
                    }
                    if (this.tabControlMain.Controls.Count==0)
                    {
                        newSelTabIndex = -1;
                    }
                    if (this.tabControlMain.Controls.Count != 0)
                    {
                        tabControlMain.SelectTab(newSelTabIndex);
                    }
                    
                    return;
                }
            }
        }

        private void splitter1_SplitterMoved(object sender, SplitterEventArgs e)
        {

        }
        private void button6_Click_1(object sender, EventArgs e)
        {
            if (isOpenTab("销售单审批"))
            {
                return;
            }

            WindowsFormsTest.Sell.SellOrderManager pp = new WindowsFormsTest.Sell.SellOrderManager();
            pp.SetModel(WindowModel.MANAGER_SEARCH);

            TabPage tb = new TabPage();
            tb.Text = "销售单审批";
            tb.Controls.Add(pp);
            tb.TabIndex = this.tabControlMain.Controls.Count;
            this.tabControlMain.TabPages.Add(tb);
            this.tabControlMain.SelectedTab = tb;
        }
        private void button8_Click(object sender, EventArgs e)
        {
            if (isOpenTab("采购订单审批"))
            {
                return;
            }
            WindowsFormsTest.Purchase.PurchaseOrderManager pp = new Purchase.PurchaseOrderManager();
            pp.setModel(ManagerModel.SEARCH);
            pp.SetMainForm(this);
            TabPage tb = new TabPage();
            tb.Text = "采购订单审批";
            tb.Controls.Add(pp);
            tb.TabIndex = this.tabControlMain.Controls.Count;
            this.tabControlMain.TabPages.Add(tb);
            this.tabControlMain.SelectedTab = tb;
        }
        private void button31_Click(object sender, EventArgs e)
        {

            if (isOpenTab(Operator.GetOperatorLabelText(OperatorLabelEnum.ORDER_MANAGER)))
            {
                return;
            }
            SellOrderManager pp = new SellOrderManager();

            Operator.Create_MainTabPage(OperatorLabelEnum.ORDER_MANAGER, pp, WindowModel.DEFAULT, this);

        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.tabControlNavigation.SelectedIndex = 0;
        }
        private void button48_Click(object sender, EventArgs e)
        {
            this.tabControlNavigation.SelectedIndex = 1;
        }

        private void button47_Click(object sender, EventArgs e)
        {
            this.tabControlNavigation.SelectedIndex = 2;
        }

        private void button46_Click(object sender, EventArgs e)
        {
            this.tabControlNavigation.SelectedIndex = 3;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.tabControlNavigation.SelectedIndex = 5;
         
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.tabControlNavigation.SelectedIndex = 4;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.tabControlNavigation.SelectedIndex = 6;
        }
        private void button15_Click(object sender, EventArgs e)
        {

            if (isOpenTab(Operator.GetOperatorLabelText(OperatorLabelEnum.ORDER_ADD)))
            {
                return;
            }
            SellOrderAdd pp = new SellOrderAdd();

            Operator.Create_MainTabPage(OperatorLabelEnum.ORDER_ADD, pp, WindowModel.DEFAULT, this);

        }

        

        private void button32_Click(object sender, EventArgs e)
        {

            if (isOpenTab(Operator.GetOperatorLabelText(OperatorLabelEnum.ORDER_REJECT)))
            {
                return;
            }
            SellOrderManager pp = new SellOrderManager();
            pp.SetModel(WindowModel.MANAGER_SEARCH);

            Operator.Create_MainTabPage(OperatorLabelEnum.ORDER_REJECT, pp, WindowModel.DEFAULT, this);


           
        }

        private void button34_Click(object sender, EventArgs e)
        {

        }

     

        public bool isOpenTab(string text){

            for (int i = 0; i < this.tabControlMain.TabPages.Count; i++)
            {
                if (this.tabControlMain.TabPages[i].Text.Equals(text))
                {
                    this.tabControlMain.SelectedTab = this.tabControlMain.TabPages[i];
                    return true;
                }
            }
            return false;
        }


        private void button43_Click(object sender, EventArgs e)
        {
            if (isOpenTab("仓库管理"))
            {
                return;
            }
            WindowsFormsTest.BusiManager.StorageManager dm = new BusiManager.StorageManager();
            TabPage tb = new TabPage();
            tb.Text = "仓库管理";
            tb.Controls.Add(dm);
            tb.TabIndex = this.tabControlMain.Controls.Count;
            this.tabControlMain.TabPages.Add(tb);
            this.tabControlMain.SelectedTab = tb;
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (isOpenTab("客户管理"))
            {
                return;
            }
            WindowsFormsTest.BusiManager.ProviderManager dm = new BusiManager.ProviderManager();
            TabPage tb = new TabPage();
            tb.Text = "客户管理";
            tb.Controls.Add(dm);
            tb.TabIndex = this.tabControlMain.Controls.Count;
            this.tabControlMain.TabPages.Add(tb);
            this.tabControlMain.SelectedTab = tb;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            if (isOpenTab("供应商管理"))
            {
                return;
            }
            WindowsFormsTest.BusiManager.ProviderManager dm = new BusiManager.ProviderManager();
            TabPage tb = new TabPage();
            tb.Text = "供应商管理";
            tb.Controls.Add(dm);
            tb.TabIndex = this.tabControlMain.Controls.Count;
            this.tabControlMain.TabPages.Add(tb);
            this.tabControlMain.SelectedTab = tb;
        }

      
      


        public TabControl GetMainTabControl()
        {
            return this.tabControlMain;
        }

        private void button7_Click_1(object sender, EventArgs e)
        {

        }


        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            ReserveSearchForm rs = new ReserveSearchForm();
            rs.Show();
        }

        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            ProcessStartInfo Info = new ProcessStartInfo();
            Info.FileName = "calc.exe";
            Process Proc = Process.Start(Info);
        }
        private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (isOpenTab(Operator.GetOperatorLabelText(OperatorLabelEnum.HOME)))
            {
                return;
            }
            IndexTab pp = new IndexTab();

            Operator.Create_MainTabPage(OperatorLabelEnum.HOME, pp, WindowModel.DEFAULT, this);

          
        
        }

        private void MainForm_Resize(object sender, EventArgs e)
        {
           
            this.tabControlMain.Dock = System.Windows.Forms.DockStyle.Fill;
        }

        private void splitContainerLR_DoubleClick(object sender, EventArgs e)
        {
            MessageBox.Show("haha");
        }

        private void button25_Click(object sender, EventArgs e)
        {

        }

        private void button26_Click(object sender, EventArgs e)
        {

        }

        private void button29_Click(object sender, EventArgs e)
        {

        }

        private void button30_Click(object sender, EventArgs e)
        {

        }

        private void button56_Click(object sender, EventArgs e)
        {

        }

        private void flowLayoutPanel7_Paint(object sender, PaintEventArgs e)
        {

        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Purchase.ProviderPriceSearchForm f = new Purchase.ProviderPriceSearchForm();
            f.Show();
        }

    }
}
